<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layouts/layout}">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <meta name="_csrf" th:content="${_csrf.token}"/>
    <meta name="_csrf_header" th:content="${_csrf.headerName}"/>
    <title>推广人员管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">

    <!-- Open Sans font from Google CDN -->
    <![endif]-->

    <style>
        .table-bordered th{
            text-align: center;
        }
        .table-bordered td{
            word-break:break-all; word-wrap:break-all;
        }
    </style>
</head>

<body class="theme-default main-menu-animated">


<th:block layout:fragment="content">
    <div class="col-xs-12 col-sm-12">
        <button  class="btn btn-info"  th:onclick="'javascript:addcatelog(this,88);'" >添加</button> &nbsp;&nbsp;
        <table id="infotable" class="table table-bordered table-hover">
            <thead>
            <tr>
                <th>#</th>
                <th>添加时间</th>
                <th>级别</th>
                <th>名称</th>
                <th>上级名称</th>
                <th>推广码</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="catelog,inx :${catelogs}">
                <td th:text="${inx.index}">1</td>
                <td th:text="${#dates.format(catelog.getCreatedAt(),'yyyy-MM-dd HH:mm:ss')}"></td>
                <td th:text="${catelog.code}">Mark</td>
                <td th:text="${catelog.nickname}"></td>
                <td th:text="${catelog.parentnickname}">Mark</td>
                <td th:text="${catelog.referral}">Mark</td>
                <td th:text="${catelog.status}">1</td>
                <td>
                    <button  class="btn btn-info"  th:onclick="'javascript:addcatelog(this,'+${catelog.code}+');'" >添加下级</button> &nbsp;&nbsp;
                    <button  class="btn btn-info"  th:onclick="'javascript:seelink(this,\''+${catelog.referral}+'\');'" >推广链接</button>

                    <button class="btn btn-success" th:onclick="'javascript:editcatelog(this,\''+${catelog.id}+'\');'" >编辑</button>


                    <button class="btn btn-success" th:onclick="'javascript:createuser(this,\''+${catelog.id}+'\');'">创建登录用户</button>
                </td>
            </tr>

            </tbody>
        </table>
    </div>
    <div class="tableFootLine">
        <div class="pagebarList pagination"/>
    </div>

    <script>

        function seelink(o,referral){
            bootbox.alert({
                message: "http://172.93.35.247/www/items/1?code=" +referral,
                className: "bootbox-sm"
            });
        }

        function addcatelog(o,code) {

            bootbox.prompt({
                title: "添加推广人员名字",
                callback: function(result) {

                    if(result === null ||result.length < 2){
                        $.growl.error({ message: "必须两个字"});
                        return;
                    }
                    $.get('/catelog/addcatelog',{nickname:result,code:code},function(res){
                        $.growl.notice({ message: res});
                    });
                },
                className: "bootbox-sm"
            });
        }
        function editcatelog(o,id) {
                var _self = o;

            bootbox.prompt({
                title: "修改推广人员名字(不能修改推广码)",
                callback: function(result) {
                    if(result === null || result.length < 2){
                        $.growl.error({ message: "必须两个字"});
                        return;
                    }

                    $.get('/catelog/editcatelog',{nickname:result,id:id},function(res){
                        $.growl.notice({ message: res});
                    });
                },
                className: "bootbox-sm"
            });
        }

        function createuser(o,id) {
            var _self = o;

            bootbox.prompt({
                title: "填写登录手机号",
                callback: function(result) {
                    if(result === null || result.length < 11){
                        $.growl.error({ message: "必须11位数字"});
                        return;
                    }

                    $.get('/catelog/createuser',{mobile:result,id:id},function(res){
                        $.growl.notice({ message: res});
                    });
                },
                className: "bootbox-sm"
            });
        }


    </script>
</th:block>
</body>
</html>